const mysql = require('../data/conn');

module.exports.index = (req, res) => {
    if (!req.session.iswangren) {
        res.redirect('/login');
        return;
    }
    res.render('./wmr/index');
}
// 显示所有文章数据
module.exports.indexShow = (req, res) => {
    mysql.query('select * from book', (error, reslut) => {
        if (error) return console.log(error);
        res.json(reslut);
    })
}
module.exports.indexDown = (req, res) => {
    mysql.query('select * from atten', (error, reslut) => {
        if (error) return console.log(error);
        res.json(reslut);
    })
}
module.exports.indexAdd = (req, res) => {
    // console.log(req.query.truru);
    // mysql.query('select atten.atten_name as name,atten.atten_tit as tit,datum.dat_homepage as homepage   from atten join datum on atten.prrid <=> datum.prrid group by atten.atten_name', (error, reslut) => {    
    // })
    mysql.query('select atten.atten_name as name,atten.atten_tit as tit,datum.dat_homepage as homepage   from atten join datum on atten.prrid <=> datum.prrid where datum.dat_homepage like "%'+req.query.truru+'%"  group by atten.atten_name',(error,data)=>{
        if(error) return console.log(error);
        // console.log(data);
        res.json(data);
    })
}

